package music.user.validation;

import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ValidateUserServlet extends HttpServlet {

    public void doPost(HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, ServletException {

        String referer = request.getHeader("Referer");

        URL url_ref = null;
        URI uri_ref = null;

        String url = "/";

        // Create a URL object
        if (referer != null) {
            url = referer;
            try {

                url_ref = new URL(referer);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }

            try {
                uri_ref = new URI(url_ref.toString());
                URI host = new URI("http://134.154.14.153:8080/yuliana");
                url = "/" + host.relativize(uri_ref).toString();
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }

        }
        System.out.println(url);

        RequestDispatcher dispatcher =
                getServletContext().getRequestDispatcher(url);
        dispatcher.forward(request, response);
    }

    public void doGet(HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }
}
